package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.DefaultValueEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.SummaryTypeEnum;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.MarketActivityEnum;
import com.xbongbong.saas.enums.dictionary.MarketActivityGenreEnum;
import com.xbongbong.saas.enums.dictionary.MarketActivityStatusEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 *市场活动初始化解释枚举
 * @author qcy
 * @date 2020/11/3
 * @since v1.0
 * @version v1.0
 */
@Getter
public enum TempMarketActivityEnum {
    BASE_INFO(MarketActivityEnum.BASE_INFO),
    NAME(MarketActivityEnum.NAME),
    START_TIME(MarketActivityEnum.START_TIME),
    END_TIME(MarketActivityEnum.END_TIME),
    GENRE(MarketActivityEnum.GENRE),
    ESTIMATE_COST(MarketActivityEnum.ESTIMATE_COST),
    REAL_COST(MarketActivityEnum.REAL_COST),
    ESTIMATE_INCOME(MarketActivityEnum.ESTIMATE_INCOME),
    REAL_INCOME(MarketActivityEnum.REAL_INCOME),
    LABEL(MarketActivityEnum.LABEL),
    OWNER_ID(MarketActivityEnum.OWNER_ID),
    COUSERID(MarketActivityEnum.COUSERID),
    STATUS(MarketActivityEnum.STATUS),
    CAPTION(MarketActivityEnum.CAPTION),
    ADDRESS(MarketActivityEnum.ADDRESS),
    MEMO(MarketActivityEnum.MEMO),
    SYSTEM_INFO(MarketActivityEnum.SYSTEM_INFO),
    CREATOR_ID(MarketActivityEnum.CREATOR_ID),
    ADD_TIME(MarketActivityEnum.ADD_TIME),
    UPDATE_TIME(MarketActivityEnum.UPDATE_TIME),
    ;
    private MarketActivityEnum anEnum;

    TempMarketActivityEnum(MarketActivityEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempMarketActivityEnum> getAllEnum() {
        List<TempMarketActivityEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initOwnerId(FieldAttrEntity fieldAttrEntity){
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setShowEditable(0);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setSetType(2);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue(DefaultValueEnum.LOGIN_USER.getValue());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        //可新增权限：超级管理员、老板、销售主管、创建人、负责人、负责人主管
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setSetType(3);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    public static void initName(FieldAttrEntity fieldAttrEntity) {
        // headList 中的 linkDetail 属性用于列表页 展示的时候，打开详情页
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.MARKET_ACTIVITY.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.MARKET_ACTIVITY.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(NAME.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initStartTime(FieldAttrEntity fieldAttrEntity) {
        //时间类型默认设置为"日期" ( IsForbidden == 0 && visable == 1 ) 时，勾选可见并且置灰
        fieldAttrEntity.setDateType("yyyy-MM-dd");
        //设置不允许“禁用”
        fieldAttrEntity.setIsForbidden(1);
    }

    public static void initEndTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType("yyyy-MM-dd");
        fieldAttrEntity.setIsForbidden(1);
    }

    public static void initEstimateCost(FieldAttrEntity fieldAttrEntity) {
        //默认精度 设置为 2
        fieldAttrEntity.setAccuracy(2);
        //默认勾选"计算数据汇总值"
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        //默认勾选“是否启用为金额”
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initRealCost(FieldAttrEntity fieldAttrEntity) {
        //默认精度 设置为 2
        fieldAttrEntity.setAccuracy(2);
        //默认勾选"计算数据汇总值"
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        //默认勾选“是否启用为金额”
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initEstimateIncome(FieldAttrEntity fieldAttrEntity) {
        //默认精度 设置为 2
        fieldAttrEntity.setAccuracy(2);
        //默认勾选"计算数据汇总值"
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        //默认勾选“是否启用为金额”
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initRealIncome(FieldAttrEntity fieldAttrEntity) {
        //默认精度 设置为 2
        fieldAttrEntity.setAccuracy(2);
        //默认勾选"计算数据汇总值"
        fieldAttrEntity.setSummaryFlag(SummaryTypeEnum.SUM.getType());
        //默认勾选“是否启用为金额”
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initGenre(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(MarketActivityGenreEnum.class, fieldAttrEntity.getFieldType()));
        //这个是把"其他放在默认里面"
        for(ItemPoJo item : fieldAttrEntity.getItems()){
            if(MarketActivityGenreEnum.OTHER.getCode().equals(item.getValue())){
                item.setIsOther(1);
                //前端展示的是 value值 ， 这里把code设置空串
                item.setValue("");
            }
        }
        //这个是设置“可以添加其他项”
        fieldAttrEntity.setDictionaryFlag(1);

    }

    public static void initStatus(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(MarketActivityStatusEnum.class, fieldAttrEntity.getFieldType()));
        //设置默认展示"已计划"
        for(ItemPoJo item : fieldAttrEntity.getItems()){
            if(MarketActivityStatusEnum.PLANNED.getCode().equals(item.getValue())){
                item.setChecked(true);
            }
        }
        fieldAttrEntity.setDictionaryFlag(1);
    }
    //设置新建，编辑页面不展示 系统字段（新建，编辑时 ，会根据unableEditMemo的值， 设置属性visible 为 0 ）
    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

}
